<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <form action="">
    <input type="text">
    <button type="submit">点击获取学生信息</button>
  </form>
    <div id="name"></div>
    <div id="age"></div>
    <div id="sex"></div>
  <script>
    //获取dom节点
    let oForm = document.querySelector('form')
    let oIpt = document.querySelector('input')
    let oName = document.querySelector('#name')
    let oAge = document.querySelector('#age')
    let oSex = document.querySelector('#sex')
    //给form绑定事件
    oForm.onsubmit = ()=>{
      //获取输入的信息
      let userId = oIpt.value
      console.log(userId);
      //实列化xml
      let xhr = new XMLHttpRequest()
      //打开路径
      //三个参数：第一个参数请求方式，第二个参数请求地址，第三个参数是否异步
      xhr.open('get',`/usera?userId=${userId}&time=${Date.now()}`,true)
      //发送请求
      xhr.send()
      //绑定监听事件
      xhr.onreadystatechange=()=>{
        if(xhr.readyState === 4){
          console.log(xhr.responseText);
        }
        
      }
    }
  </script>
</body>

</html>